package com.hezuti.common.utils;

import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class EncodeUtil {
	public static String encodeByMAB(String str) throws NoSuchAlgorithmException{
		MessageDigest md=MessageDigest.getInstance("MD5");
		byte[] bys = md.digest(str.getBytes());
		return encodeByBASE64(bys);
	}
	
	public static String encodeByBASE64(byte[] bys){
		BASE64Encoder be=new BASE64Encoder();
		return be.encode(bys);
	}
	public static byte[] decodeByBASE64(String str) throws IOException{
		BASE64Decoder be=new BASE64Decoder();
		return be.decodeBuffer(str);
	}
	public static void main(String[] args) {
		try {
			System.out.println(EncodeUtil.encodeByMAB("ABCDEF"));
			System.out.println(EncodeUtil.encodeByMAB("4545"));
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		
	}
}
